<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>材料签收</title>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/bootstrap.min.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/jedate.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/fonts/iconfont.css"/>
		<link rel="stylesheet" type="text/css" href="../../../resource/css/common.css"/>
		<style type="text/css">
			/*.erp-txt span{width: 95px;}*/
			.mat-num{width: 50px;text-align: center;display: inline-block;}
			.mat-dw{margin-left: 10px;}
			.sign-peoper{text-align: left;padding-bottom: 20px; margin: 0 auto;}
			.sign-peoper span{ width: 180px;}
			.sign-peoper input{ width: 100%; border:1px solid #ccc; height: 35px; text-indent: 24px;}
			.order-li{height: auto;}
			.btn-warning{background-color: #ff5622; border-color: #ff5622;}
			
		</style>
	</head>
	<body>
		<div class="container-fluid">
			<div class="row mheader">
				<div class="col-xs-2 text-left"><a href="javascript:;" onclick="javascript:history.back(-1);"><span class="iconfont icon-fanhui"></span></a></div>
				<div class="col-xs-8"><h2>材料签收</h2></div>
			</div>
			<div class="row">
				<!-- 头部 -->
				<dl class="erp-list erp-details" id="ttt">

				</dl>
				<!-- 详情 -->
				<dl class="erp-order" id="sss">

				</dl>
			</div>
			<input type="button" class="btn btn btn-success btn-block" value="签收" onclick="tj()">
			<input type="button" class="btn btn-danger btn-block" value="拒绝签收" onclick="noSign()">
			<div style="margin-bottom: 80px;"></div>
		</div>
	</body>
</html>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="../../../resource/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../resource/js/style.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../resources/js/template-web.js" type="text/javascript" charset="utf-8"></script>
<script id="t" type="text/html">
	<dl class="erp-list erp-details">
		<dd>
			<div class="erp-txt visa-txt">
				<input name="rm_code" value="{{rm_code}}" type="hidden">
				<p><span>供料单号:</span>{{rm_code}}</p>
				<p class="clearfix"><span class="sp">项目名称:</span><span class="divCon">{{proName}}</span></p>
				<p class="clearfix"><span class="sp">供货地址:</span><span class="divCon">{{r_adr}}</span></p>
				<p><span>供货时间:</span>{{rm_Time}}</p>
				<p><span>签收状态:</span>{{validate}}</p>
				<p><span>审核状态:</span>{{state}}</p>
			</div>
		</dd>
	</dl>
</script>
<script id="m_list" type="text/html">
	{{each data as value i}}
		<dd>
			<p><span>材料名称:</span>{{value.mat_Name}}</p>
			<div class="order-li clearfix">
				<input type="hidden" name="mat_id" value="{{value.id}}">
				<div class="col-xs-6"><span>规格:</span>{{value.mat_Spec}}</div>
				<div class="col-xs-6"><span>送料数量:</span>{{value.send_Num}}</div>
				<div class="col-xs-6"><span>单位:</span>{{value.mat_Bit}}</div>
				<div class="col-xs-6">
					<span>签收数量:</span>
					<input type="number" class="mD-num" name="qsNum"  value="{{value.send_Num}}" />
				</div>
			</div>
		</dd>
	{{/each}}
	<dd>
		<div class="sign-peoper">
			<p><span>收料单位及经手人：</span><input type="text" name="recvName" id="" value="" /></p>
			<p><span>收料单位及经手人意见：</span><input type="text" name="recvName_Opinion" id="" value="" /></p>
		</div>
	</dd>
</script>
<script type="text/javascript">

    //获取列表页的内容
    var obj = sessionStorage.getItem("obj");
    obj = JSON.parse(obj);

    //传入id来进行渲染
    var html = template('t', obj);
    document.getElementById('ttt').innerHTML =  html;
    //详情
    loadDetails();
    /**
     * 	加载详情
     */
    function loadDetails() {
        gundong(function(){
            ajaxs('api/ctteam/matSignDetails.do',
                'post',
                {'rm_code':obj.rm_code,'p':getP()},
                function (data) {
                    console.log(data);
                    //传入id来进行渲染
                    var html = template('m_list', data);
                    document.getElementById('sss').innerHTML =  html;
                });
        }());
    }





    /**
	 * 	提交
     */
    function tj() {
		//拼接数据
        var sd = '';
        $(".order-li").each(function(){
		    var mat_id = $(this).find("input[name='mat_id']").val();
		    var rm_num = $(this).find("input[name='qsNum']").val();
		    sd += mat_id + ',';
		    sd += rm_num + '|';
		});
		sd = sd.substr(0,sd.lastIndexOf("|"));
        var recvName = $("input[name='recvName']").val();
        var recvName_Opinion = $("input[name='recvName_Opinion']").val();
        var rm_code = $("input[name='rm_code']").val();
        if ( recvName== "" ){
            window.tool.alert("收料人不能为空");
            return false;
		}
		console.log(recvName,recvName_Opinion,rm_code,sd,getP())
        ajaxs('api/ctteam/matSign.do',
            'post',
            {'rm_code':rm_code,'recvName':recvName,'recvName_Opinion':recvName_Opinion,'sd':sd ,'p':getP()},
            function (data) {
                console.log(data)
                window.tool.alert(data.msg);
                location.href ="./erp-list.html";
			}
		);
    }

    /**
	 * 	拒绝签收
     */
    function noSign() {
        var rm_code = $("input[name='rm_code']").val();
        var recvName_Opinion = $("input[name='recvName_Opinion']").val();
        if ( recvName_Opinion== "" ){
            window.tool.alert("请给出拒绝意见");
            return false;
        }
        ajaxs('api/ctteam/matNoSign.do',
            'post',
            {'rm_code':rm_code,'recvName_Opinion':recvName_Opinion ,'p':getP()},
            function (data) {

                window.tool.alert(data.msg);
                location.href ="./erp-list.html";
            }
        );
    }


$(".check_span").click(function(){
	$(this).toggleClass("check_span--checked");
	
})
$(".allCheck").click(function(){
	
	$(".check_span").addClass("check_span--checked");

})
//$("span[class='itemCheck']").each(function(){  
//    if($("span[class='itemCheck']").hasClass("check_span--checked")){
//    	window.tool.alert(111)
//    }else{
//    	window.tool.alert(222)
//    }
// });

    $(function () {

        var arrs=getCookie('yanzheng');
        arrs=arrs.split('|');
        $('[name="recvName"]').val(arrs[0]);

        //判断数量输入框是否为空
        $('#sss .clearfix').on('focus','input',function () {
            console.log($(this))
            $(this).keyup(function () {
                console.log($(this).val()<=0)
                if($(this).val()<=0){
                    $('.btn-warning').hide();
                    window.tool.alert('数量不能小于0,请修改');
                    return;
                }else{
                    $('.btn-warning').show();
                }
            })
        })


    })

</script>